﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AgriculturalMachinery.Models
{
    public class ProductViewModel<T> : List<T>
    {
        #region 产品信息的分页代码
        public int ProductPageIndex { get; private set; }
        public int ProductPageSize { get; private set; }
        public int ProductTotalCount { get; private set; }
        public int ProductTotalPage { get; private set; }
        public IQueryable PagedAllProducts { get; private set; }
        public IQueryable AllProducts { get; private set; }
        public ProductInfo pi;

        public ProductViewModel(IQueryable<T> ProductSource, int ProductPageIndex, int ProductPageSize)
        {
            this.ProductPageIndex = ProductPageIndex;
            this.ProductPageSize = ProductPageSize;
            this.ProductTotalCount = ProductSource.Count();
            this.ProductTotalPage = (int)Math.Ceiling(ProductTotalCount / (double)ProductPageSize);
            this.PagedAllProducts = ProductSource.Skip(ProductPageIndex * ProductPageSize).Take(ProductPageSize);
        }
        public ProductViewModel()
        {
            ProductRepository pr = new ProductRepository();
            AllProducts = pr.FindAllProducts();
        }
        public ProductViewModel(int id)
        {
            ProductRepository pr = new ProductRepository();
            pi = pr.FindProductByID(id);
        }

        
        #endregion
    }
}
